#include <memory.h>
#include <stdio.h>

#define MAX(a, b) ((a) > (b) ? (a) : (b))

int gcd(int num1, int num2) {
    while (num2 != 0) {
        int temp = num1;
        num1 = num2;
        num2 = temp % num2;
    }
    return num1;
}

int maxScore(int *nums, int numsSize) {
    int dp[1 << numsSize];
    int gcd_tmp[numsSize][numsSize];
    memset(dp, 0, sizeof(dp));
    memset(gcd_tmp, 0, sizeof(gcd_tmp));
    for (int i = 0; i < numsSize; ++i) {
        for (int j = 0; j < numsSize; ++j) {
            gcd_tmp[i][j] = gcd(nums[i], nums[j]);
        }
    }
    int all = 1 << numsSize;
    for (int s = 1; s < all; ++s) {
        int t = __builtin_popcount(s);
        if (t & 1) {
            continue;
        }
        for (int i = 0; i < numsSize; ++i) {
            if ((s >> i) & 1) {
                for (int j = i + 1; j < numsSize; ++j) {
                    if ((s >> j) & 1) {
                        dp[s] = MAX(dp[s], dp[s ^ (1 << i) ^ (1 << j)] + t / 2 * gcd_tmp[i][j]);
                    }
                }
            }
        }
    }
    return dp[all - 1];
}

int main() {
    int nums[2] = {1, 2};
    int ret = maxScore(nums, 2);
    printf("%d", ret);
}
